package com.jackrain.clouddata.sys.Listenter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import com.aliyun.openservices.ons.api.impl.util.MsgConvertUtil;
import com.jackrain.clouddata.oms.dao.RetPurDao;
import com.jackrain.nea.config.PropertiesConf;
import com.jackrain.nea.core.db.Tools;
import com.jackrain.nea.exception.NDSException;
import com.jackrain.nea.util.ApplicationContextHandle;
import com.jackrain.nea.util.tlock.RedisReentrantLock;
import com.jackrain.nea.web.query.QueryEngine;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
 * 消费云数据消息
 */
@Component("com.jackrain.clouddata.sys.Listenter.Ret_PurMessageProcess")
@Slf4j
public class Ret_PurMessageProcess implements MessageProcess {
    private static final Logger logger = LoggerFactory.getLogger(Ret_PurMessageProcess.class);
    public Ret_PurMessageProcess() {

    }

    @Override
    public void process(Object paramObject, String tag) throws Exception{
        RetPurDao retPurDao = ApplicationContextHandle.getBean(RetPurDao.class);
        JSONArray paramArray = JSONObject.parseArray(JSON.toJSONString(paramObject, new SerializerFeature[]{SerializerFeature.WriteNullStringAsEmpty}));
        for (int i = 0; i < paramArray.size(); i++) {
            try {
                retPurDao.insert(paramArray.getJSONObject(i), tag);
            } catch (SQLException e) {
                throw e;
            }
        }
    }
}